﻿define(function (require) {
    $(function () {
        var service = require('ezdesk/utility/service');
        var utility = require('ezdesk/utility/utility.js');

        require('model/Workitem');
        require('model/WorkitemList');

        var WorkitemListView = require('view/WorkitemListView');

        var refreshWorkitems = function () {
            utility.AjaxLoad.AjaxLoadBegin();

            service.GetWorkitems(function (workitemList) {
                utility.AjaxLoad.AjaxLoadEnd();
                workitemsView.model.reset(workitemList);
                workitemsView.render();
            })
        }

        var workitemsView = new WorkitemListView({ model: new WorkitemList });

        workitemsView.bind('empty', function () {
            $('.ui-remind').html('没有任务').show();
        });


        $.receiveMessage(function (e) {
            var paramKeyRegex = /\w*(?=\:)/g;
            var key = paramKeyRegex.exec(e.data);
            key = key ? key[0] : e.data;

            if (key == 'show')
                refreshWorkitems();
        });

       
        refreshWorkitems();
        
    })
})
